#include "specparam.h"
#include "earthquake_global.h"
#include "QtDebug.h"

string SpecParam::m_objname = "SpecParam";

SpecParam::SpecParam() :
    m_agn(0),
    m_Fo(0),
    m_Tsc(0),
    m_is_agn(false),
    m_is_Fo(false),
    m_is_Tsc(false),
    m_empty(true)
{

}

SpecParam::SpecParam(const PKeyList* plist) :
    m_agn(0),
    m_Fo(0),
    m_Tsc(0),
    m_is_agn(false),
    m_is_Fo(false),
    m_is_Tsc(false),
    m_empty(true),
    PKeyItem(plist->getListId()),
    PRef(plist)
{

}

SpecParam::SpecParam(const double& agn, const double& Fo, const double& Tsc) :
    Customizable(true)
{
	set(agn,Fo,Tsc);
}

SpecParam::SpecParam(
        const double& agn,
        const double& Fo,
        const double& Tsc,
        const PKeyItem& key,
        const PRef& ref
        ) :
    PKey(key),
    PItem(key),
    PRef(ref),
    Customizable(true)
{
    set(agn,Fo,Tsc);
}

SpecParam::SpecParam(const SpecParam& sp) :
    Customizable(sp),
    PKey(sp),
    PItem(sp),
    PRef(sp)
{
	  m_agn = sp.m_agn;
	   m_Fo = sp.m_Fo;
	  m_Tsc = sp.m_Tsc;

	m_is_agn = sp.m_is_agn ;
	m_is_Fo  = sp.m_is_Fo  ;
	m_is_Tsc = sp.m_is_Tsc ;

	m_empty = sp.m_empty;
}

SpecParam& SpecParam::operator=(const SpecParam& sp)
{   
    // Per la classe [SpecParam]
      m_agn = sp.m_agn;
       m_Fo = sp.m_Fo;
	  m_Tsc = sp.m_Tsc;

	m_is_agn = sp.m_is_agn ;
     m_is_Fo = sp.m_is_Fo  ;
	m_is_Tsc = sp.m_is_Tsc ;

	m_empty = sp.m_empty;

    // Per la classe [PKey]
    // PKey::operator = ( sp );
    setKeyStr(sp.getKeyStr());
    setDescr(sp.getDescr());
    if ( sp.getTabRef() != EXA_TAB_NULL )
    {
        setTabRef(sp.getTabRef());
    }

    // Per la classe [PRef]
    PRef::operator = ( sp );

    // Per la classe [Customizable]
    Customizable::operator = ( sp );

	return *this;
}

double SpecParam::agn(void) const{
	return m_agn;
}

double  SpecParam::Fo(void) const{
	return m_Fo;
}

double SpecParam::Tsc(void) const{
	return m_Tsc;
}

void SpecParam::set(const double& agn, const double& Fo, const double& Tsc)
{
	set_agn(agn);
	set_Fo(Fo);
	set_Tsc(Tsc);
}

void SpecParam::set_agn(const double& agn){
	if (agn >=0)
	{
		m_agn = agn;
		m_is_agn = true;
		m_empty = false;
	}
	else
	{
		m_is_agn = false;
	}
}

void  SpecParam::set_Fo(const double& Fo){
	if (Fo >= 0)
	{
		m_Fo = Fo;
		m_is_Fo  = true;
		m_empty = false;
	}
	else
	{
		m_is_Fo  = false;
	}
}

void SpecParam::set_Tsc(const double& Tsc){
	if (Tsc >= 0)
	{
		m_Tsc = Tsc;
		m_is_Tsc = true;
		m_empty = false;
	}
	else
	{
		m_is_Tsc = false;
	}
}

bool SpecParam::isEmpty(void) const {
	return m_empty;
}

bool SpecParam::isComplete(void) const {
    return (m_is_agn && m_is_Fo && m_is_Tsc);
}

bool SpecParam::isNull(void) const {
	return (m_agn == 0 || m_Fo == 0 || m_Tsc == 0);
}

void SpecParam::setCustom(const bool& cust)
{
    Customizable::setCustom(cust);
    if (cust == true)
    {
        delRefFrom(EXA_TAB_TEMPIRITORNO);
    }
    else
    {

    }
}

void SpecParam::reportMake(const string& objname) const
{
    if (getReportCurrentStyle() == STYLE_VERBOSE)
    {
        PReport::resetReportOpt();
        PReport::setReportOpt("SUB",true);
        PKeyItem::reportMake();
        Customizable::reportMake();
        PRef::reportMake();
        PReport::setReportOpt("SUB",false);
        moveLineInBlock(string("VALORI"));
        addInLine("agn",m_agn);
        addInLine("Fo",m_Fo);
        addInLine("Tsc",m_Tsc);
        moveLineInBlock();
        moveLineInBlock(string("STATI"));
        addInLine("empty",isEmpty());
        addInLine("complete",isComplete());
        addInLine("null",isNull());
        moveLineInBlock();
    }
    else if (getReportCurrentStyle() == STYLE_COMPACT)
    {
        addInLine("ID",getKeyStr(),10);
        addInLine("des.",getDescr());
        addInLine("TAB",getTabRef(),2);
        addInLine("agn",m_agn,5,3);
        addInLine("Fo",m_Fo,5,3);
        addInLine("Tsc",m_Tsc,5,3);
        addInLine("ID.Tr",getRefFrom(EXA_TAB_TEMPIRITORNO).getKeyStr(),10);
        moveLineInBlock();
    }
    PReport::reportMake(m_objname);
}
